package com.visionet.school.app.web.repository.dynamic;

import com.visionet.school.app.web.entity.dynamic.DynamicComment;
import com.visionet.school.app.web.entity.dynamic.DynamicCommentLikes;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

/**
 * Created by hxpeng on 2017/5/27.
 */
@Repository
public interface DynamicCommentLikesRepository extends PagingAndSortingRepository<DynamicCommentLikes,String>,JpaSpecificationExecutor<DynamicCommentLikes> {


    /**
     * 评论点赞数量
     * @param commentId
     * @return
     */
    @Query("select count(id) from DynamicCommentLikes as dc where dc.isDeleted = 0 and dc.commentId = ?1 ")
    int dynamicCountLikesCount(String commentId);



    /**
     * 用户是否已经点赞此评论
     * @param commentId
     * @return
     */
    @Query("select count(id) from DynamicCommentLikes as dc where dc.isDeleted = 0 and dc.commentId = ?1 and dc.memberId = ?2 ")
    int commentHadLikes(String commentId, String memberId);


}
